<template>
    <div class="app-container">
        <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" @export="handleExport">
        </wms-form>
        <wms-table :loading="loading" :data-list="stockList" :column="column" :pageInfo="queryParams"
            @get-list="getList" @selection-change="handleSelectionChange" />
    </div>
</template>

<script setup name="Stock">
import { listStock, disablesStock, directOut } from "@/api/wms/stock";
import WmsForm from '@/components/WmsForm/index.vue'
import WmsTable from '@/components/WmsTable/index.vue'
import { data, column, formList } from './index.js'
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);
const stockList = ref([]);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const selectedStocks = ref([]);

/** 查询库存查询列表 */
function getList() {
    loading.value = true;
    queryParams.overdueFlag = '1';
    listStock(proxy.addDateRange(queryParams, queryParams.dateRange)).then(response => {
        stockList.value = response.rows;
        queryParams.total = response.total;
        loading.value = false;
    });
}


/** 搜索按钮操作 */
function handleQuery() {
    queryParams.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParams.dateRange = [];
    proxy.resetForm("queryRef");
    handleQuery();
}
// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.stockId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
    selectedStocks.value = selection;
}

// 暴露选中的库存项
defineExpose({
    getSelectedStocks: () => selectedStocks.value
})

/** 导出按钮操作 */
function handleExport() {
    proxy.download('${moduleName}/${businessName}/export', {
        ...queryParams
    }, `${businessName}_#[[${new Date().getTime()}.xlsx`)
}
getList();
</script>
